package com.ydd.controller.admin;

import com.ydd.dto.SelectAllDTO;
import com.ydd.dto.YddLinkDTO;
import com.ydd.entity.YddLink;
import com.ydd.result.PageResult;
import com.ydd.result.Result;
import com.ydd.service.IYddLinkService;
import com.ydd.vo.YddLinkVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/ydd_link")
@Api(tags = "友情链接管理")
@Slf4j
public class YddLinkController {

    @Autowired
    private IYddLinkService IYddLinkService;

    /**
     * 分页查询友情链接
     * @param selectAllDTO
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("友情链接")
    public Result pageQuery(SelectAllDTO selectAllDTO){
        PageResult pageResult = IYddLinkService.clickLink(selectAllDTO);
        return Result.success(pageResult);
    }

    /**
     * 链接修改
     * @return
     */
    @PostMapping("/update")
    @ApiOperation("链接修改")
    public Result update(@RequestBody YddLinkDTO yddLinkDTO){
        log.info("链接修改:{}",yddLinkDTO);
        IYddLinkService.update(yddLinkDTO);
        return Result.success();
    }

    /**
     * qbs
     * 新增友情链接
     * @param yddLink
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("新增友情链接")
    public Result addLink(@RequestBody YddLink yddLink){
        IYddLinkService.addLink(yddLink);
        return Result.success();
    }

    /**
     * qbs
     * 删除友情链接
     * @return
     */
    @GetMapping("/del")
    @ApiOperation("删除友情链接")
    public Result deleteLink(String id){
        IYddLinkService.deleteLink(id);
        return Result.success();
    }

    /**
     * qbs
     * 链接详情
     * @return
     */
    @GetMapping("/rowInfo")
    @ApiOperation("链接详情")
    public Result<YddLinkVO> rowInfo(String id){
        YddLinkVO yddLinkVO = IYddLinkService.rowInfo(id);
        return Result.success(yddLinkVO);
    }
}


